package com.baturu.offlineFord;

import com.baturu.ford.carvin.dal.MappingDAO;
import com.baturu.offlineFord.dto.MappingDTO;
import com.baturu.vin.test.AbstractBaseCase;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author: chenjiahao
 * @Time: 2019/3/12
 */
public class OutMapping extends AbstractBaseCase{

    @Autowired
    MappingDAO mappingDAO;

    /**
     * 导出为映射编码信息
     * @throws Exception
     */
    @Test
    public void testName() throws Exception {

        Integer maxId = mappingDAO.queryMaxId();
        Integer start = 0;
        for (Integer i = 0; i < maxId; i++) {
            if (i%10000==0 && i!=0) {
                List<MappingDTO> mappingDTOs = mappingDAO.queryPartsInfo(start,i);
                mappingDTOs.forEach(d ->{
                    List<String> name = Splitter.on(" ").splitToList(d.getEpcPartsName());
                    List<String> l = mappingDAO.queryName(name);
                    String join = StringUtils.join(l, " ");
                    d.setEpcPartsName(join);
                });
                if (CollectionUtils.isNotEmpty(mappingDTOs)) {
                    mappingDAO.insertImageDTO(mappingDTOs);
                }

             start = i;
            }
        }

        if (start%10000!=0) {
            List<MappingDTO> mappingDTOs = mappingDAO.queryPartsInfo(start,maxId);
            mappingDTOs.forEach(d ->{
                List<String> name = Splitter.on(" ").splitToList(d.getEpcPartsName());
                List<String> l = mappingDAO.queryName(name);
                String join = StringUtils.join(l, " ");
                d.setEpcPartsName(join);
            });
            if (CollectionUtils.isNotEmpty(mappingDTOs)) {
                mappingDAO.insertImageDTO(mappingDTOs);
            }
        }


    }
}
